package com.zzx.boot.controller;

import com.zzx.boot.entity.dto.AddPost;
import com.zzx.boot.entity.dto.SupportDto;
import com.zzx.boot.servlet.PostClassService;
import com.zzx.boot.servlet.PostService;
import com.zzx.boot.servlet.SupportService;
import com.zzx.boot.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * @author tan
 * @version 1.0
 * @date 2023/7/8 14:32
 */
@Api(tags = "文章模块")
@RestController
@RequiredArgsConstructor
@RequestMapping("/post")
public class PostController {

    private final PostClassService postClassService;
    private final PostService postService;
    private final SupportService supportService;

    @ApiOperation(value = "获取文章分类")
    @GetMapping("/class")
    public R getPostClass(){
        return postClassService.getPostClass();
    }


    @ApiOperation(value = "添加文章")
    @PostMapping("add/topic")
    public R addTopic(AddPost post){
        return postService.addTopic(post);
    }


    @ApiOperation(value = "获取文章详情")
    @PostMapping("/get/{id}/post")
    public R getPostDetail(@NotNull(message = "文章id不能为空")@PathVariable("id") Long id){
        return R.success(postService.getPostDetailById(id,true));
    }

    @ApiOperation("指定话题下的文章列表")
    @GetMapping("/topic/{topicId}/post/{current}")
    public R postByTopicPage(@PathVariable("topicId")Long topicId,@PathVariable("current") Long current){
        return R.success(postService.postByTopicPage(topicId,current));
    }

    @ApiOperation("指定文章分类下的文章列表")
    @GetMapping("/postclass/{classId}/post/{current}")
    public R postByPostClassPage(@PathVariable("classId")Long classId,@PathVariable("current") Long current){
        return R.success(postClassService.postByPostClassPage(classId,current));
    }

    @ApiOperation("指定用户下的文章列表")
    @GetMapping("/user/{userId}/post/{current}")
    public R postByUserPage(@PathVariable("userId")Long userId,@PathVariable("current") Long current){
        return R.success(postService.postByUserPage(userId,current));
    }

    @ApiOperation("搜索文章")
    @GetMapping("/search/{current}/page")
    public R postSearch(String keyword,@PathVariable("current") Long current){
        return R.success(postService.postSearch(keyword,current));
    }

    @ApiOperation("文章点赞或踩")
    @PostMapping("/support/add")
    public R addSupport(SupportDto supportDto){
        return R.success(supportService.createSupport(supportDto));
    }




}
